1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.UnixConnection; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.Credentials; 30 private import gio.SocketConnection; 31 private import gio.c.functions; 32 public import gio.c.types; 33 private import glib.ErrorG; 34 private import glib.GException; 35 private import gobject.ObjectG; 36 37 38 /** 39 * This is the subclass of #GSocketConnection that is created 40 * for UNIX domain sockets. 41 * 42 * It contains functions to do some of the UNIX socket specific 43 * functionality like passing file descriptors. 44 * 45 * Since GLib 2.72, #GUnixConnection is available on all platforms. It requires 46 * underlying system support (such as Windows 10 with `AF_UNIX`) at run time. 47 * 48 * Before GLib 2.72, `<gio/gunixconnection.h>` belonged to the UNIX-specific GIO 49 * interfaces, thus you had to use the `gio-unix-2.0.pc` pkg-config file when 50 * using it. This is no longer necessary since GLib 2.72. 51 * 52 * Since: 2.22 53 */ 54 public class UnixConnection : SocketConnection 55 { 56 /** the main Gtk struct */ 57 protected GUnixConnection* gUnixConnection; 58 59 /** Get the main Gtk struct */ 60 public GUnixConnection* getUnixConnectionStruct(bool transferOwnership = false) 61 { 62 if (transferOwnership) 63 ownedRef = false; 64 return gUnixConnection; 65 } 66 67 /** the main Gtk struct as a void* */ 68 protected override void* getStruct() 69 { 70 return cast(void*)gUnixConnection; 71 } 72 73 /** 74 * Sets our main struct and passes it to the parent class. 75 */ 76 public this (GUnixConnection* gUnixConnection, bool ownedRef = false) 77 { 78 this.gUnixConnection = gUnixConnection; 79 super(cast(GSocketConnection*)gUnixConnection, ownedRef); 80 } 81 82 83 /** */ 84 public static GType getType() 85 { 86 return g_unix_connection_get_type(); 87 } 88 89 /** 90 * Receives credentials from the sending end of the connection. The 91 * sending end has to call g_unix_connection_send_credentials() (or 92 * similar) for this to work. 93 * 94 * As well as reading the credentials this also reads (and discards) a 95 * single byte from the stream, as this is required for credentials 96 * passing to work on some implementations. 97 * 98 * This method can be expected to be available on the following platforms: 99 * 100 * - Linux since GLib 2.26 101 * - FreeBSD since GLib 2.26 102 * - GNU/kFreeBSD since GLib 2.36 103 * - Solaris, Illumos and OpenSolaris since GLib 2.40 104 * - GNU/Hurd since GLib 2.40 105 * 106 * Other ways to exchange credentials with a foreign peer includes the 107 * #GUnixCredentialsMessage type and g_socket_get_credentials() function. 108 * 109 * Params: 110 * cancellable = A #GCancellable or %NULL. 111 * 112 * Returns: Received credentials on success (free with 113 * g_object_unref()), %NULL if @error is set. 114 * 115 * Since: 2.26 116 * 117 * Throws: GException on failure. 118 */ 119 public Credentials receiveCredentials(Cancellable cancellable) 120 { 121 GError* err = null; 122 123 auto __p = g_unix_connection_receive_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 124 125 if (err !is null) 126 { 127 throw new GException( new ErrorG(err) ); 128 } 129 130 if(__p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(Credentials)(cast(GCredentials*) __p, true); 136 } 137 138 /** 139 * Asynchronously receive credentials. 140 * 141 * For more details, see g_unix_connection_receive_credentials() which is 142 * the synchronous version of this call. 143 * 144 * When the operation is finished, @callback will be called. You can then call 145 * g_unix_connection_receive_credentials_finish() to get the result of the operation. 146 * 147 * Params: 148 * cancellable = optional #GCancellable object, %NULL to ignore. 149 * callback = a #GAsyncReadyCallback to call when the request is satisfied 150 * userData = the data to pass to callback function 151 * 152 * Since: 2.32 153 */ 154 public void receiveCredentialsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 155 { 156 g_unix_connection_receive_credentials_async(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 157 } 158 159 /** 160 * Finishes an asynchronous receive credentials operation started with 161 * g_unix_connection_receive_credentials_async(). 162 * 163 * Params: 164 * result = a #GAsyncResult. 165 * 166 * Returns: a #GCredentials, or %NULL on error. 167 * Free the returned object with g_object_unref(). 168 * 169 * Since: 2.32 170 * 171 * Throws: GException on failure. 172 */ 173 public Credentials receiveCredentialsFinish(AsyncResultIF result) 174 { 175 GError* err = null; 176 177 auto __p = g_unix_connection_receive_credentials_finish(gUnixConnection, (result is null) ? null : result.getAsyncResultStruct(), &err); 178 179 if (err !is null) 180 { 181 throw new GException( new ErrorG(err) ); 182 } 183 184 if(__p is null) 185 { 186 return null; 187 } 188 189 return ObjectG.getDObject!(Credentials)(cast(GCredentials*) __p, true); 190 } 191 192 /** 193 * Receives a file descriptor from the sending end of the connection. 194 * The sending end has to call g_unix_connection_send_fd() for this 195 * to work. 196 * 197 * As well as reading the fd this also reads a single byte from the 198 * stream, as this is required for fd passing to work on some 199 * implementations. 200 * 201 * Params: 202 * cancellable = optional #GCancellable object, %NULL to ignore 203 * 204 * Returns: a file descriptor on success, -1 on error. 205 * 206 * Since: 2.22 207 * 208 * Throws: GException on failure. 209 */ 210 public int receiveFd(Cancellable cancellable) 211 { 212 GError* err = null; 213 214 auto __p = g_unix_connection_receive_fd(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 215 216 if (err !is null) 217 { 218 throw new GException( new ErrorG(err) ); 219 } 220 221 return __p; 222 } 223 224 /** 225 * Passes the credentials of the current user the receiving side 226 * of the connection. The receiving end has to call 227 * g_unix_connection_receive_credentials() (or similar) to accept the 228 * credentials. 229 * 230 * As well as sending the credentials this also writes a single NUL 231 * byte to the stream, as this is required for credentials passing to 232 * work on some implementations. 233 * 234 * This method can be expected to be available on the following platforms: 235 * 236 * - Linux since GLib 2.26 237 * - FreeBSD since GLib 2.26 238 * - GNU/kFreeBSD since GLib 2.36 239 * - Solaris, Illumos and OpenSolaris since GLib 2.40 240 * - GNU/Hurd since GLib 2.40 241 * 242 * Other ways to exchange credentials with a foreign peer includes the 243 * #GUnixCredentialsMessage type and g_socket_get_credentials() function. 244 * 245 * Params: 246 * cancellable = A #GCancellable or %NULL. 247 * 248 * Returns: %TRUE on success, %FALSE if @error is set. 249 * 250 * Since: 2.26 251 * 252 * Throws: GException on failure. 253 */ 254 public bool sendCredentials(Cancellable cancellable) 255 { 256 GError* err = null; 257 258 auto __p = g_unix_connection_send_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 259 260 if (err !is null) 261 { 262 throw new GException( new ErrorG(err) ); 263 } 264 265 return __p; 266 } 267 268 /** 269 * Asynchronously send credentials. 270 * 271 * For more details, see g_unix_connection_send_credentials() which is 272 * the synchronous version of this call. 273 * 274 * When the operation is finished, @callback will be called. You can then call 275 * g_unix_connection_send_credentials_finish() to get the result of the operation. 276 * 277 * Params: 278 * cancellable = optional #GCancellable object, %NULL to ignore. 279 * callback = a #GAsyncReadyCallback to call when the request is satisfied 280 * userData = the data to pass to callback function 281 * 282 * Since: 2.32 283 */ 284 public void sendCredentialsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 285 { 286 g_unix_connection_send_credentials_async(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 287 } 288 289 /** 290 * Finishes an asynchronous send credentials operation started with 291 * g_unix_connection_send_credentials_async(). 292 * 293 * Params: 294 * result = a #GAsyncResult. 295 * 296 * Returns: %TRUE if the operation was successful, otherwise %FALSE. 297 * 298 * Since: 2.32 299 * 300 * Throws: GException on failure. 301 */ 302 public bool sendCredentialsFinish(AsyncResultIF result) 303 { 304 GError* err = null; 305 306 auto __p = g_unix_connection_send_credentials_finish(gUnixConnection, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 307 308 if (err !is null) 309 { 310 throw new GException( new ErrorG(err) ); 311 } 312 313 return __p; 314 } 315 316 /** 317 * Passes a file descriptor to the receiving side of the 318 * connection. The receiving end has to call g_unix_connection_receive_fd() 319 * to accept the file descriptor. 320 * 321 * As well as sending the fd this also writes a single byte to the 322 * stream, as this is required for fd passing to work on some 323 * implementations. 324 * 325 * Params: 326 * fd = a file descriptor 327 * cancellable = optional #GCancellable object, %NULL to ignore. 328 * 329 * Returns: a %TRUE on success, %NULL on error. 330 * 331 * Since: 2.22 332 * 333 * Throws: GException on failure. 334 */ 335 public bool sendFd(int fd, Cancellable cancellable) 336 { 337 GError* err = null; 338 339 auto __p = g_unix_connection_send_fd(gUnixConnection, fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 340 341 if (err !is null) 342 { 343 throw new GException( new ErrorG(err) ); 344 } 345 346 return __p; 347 } 348 }